import 'package:flutter/material.dart';
import 'package:v10/login/page2.dart';

class MyHomePage extends StatefulWidget {
  @override
  createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _uNameController;
  TextEditingController _uPdController;

  @override
  void initState() {
    super.initState();
    _uNameController = new TextEditingController()
      ..text = "张三"
      ..addListener(() => print("name:${_uNameController.text}"));
    _uPdController = new TextEditingController()
      ..addListener(() => print("password:${_uPdController.text}"));
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("注册页面"),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          UserInfoEt('用户名', _uNameController),
          Container(padding: EdgeInsets.all(2.0),),
          UserInfoEt(
            '密码',
            _uPdController,
            isPd: true,
          ),
          UserInfoBt("登录", goLogin),
          Align(
            alignment: Alignment.centerRight,
            child: GestureDetector(
              onTap: () => goRegister(context),
              child: Container(
                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                  child: Text("注册")),
            ),
          ),
          Expanded(child: Container()),
          OtherLogin(goWeixin),
        ],
      ),
    );
  }

  void goLogin() {
    print("goLogin");
  }

  void goWeixin() {
    print("goWeixin");
  }

  void goRegister(context) {
    print("goRegister");
    Navigator.push(context,new MaterialPageRoute(builder: (BuildContext context){
      return new TextFieldAndCheckPage();
    }));
  }
}
class UserInfoBt extends StatelessWidget {
  String value;
  Function onPress;

  UserInfoBt(this.value, this.onPress, {Key key}) : super(key: key);
  RaisedButton rb;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: this.onPress,
        child: Container(
          margin: EdgeInsets.all(10.0),
          padding: EdgeInsets.all(10.0),
          decoration: BoxDecoration(
              color: Colors.orangeAccent,
              borderRadius: BorderRadius.all(Radius.circular(5.0))),
          child: Flex(
              direction: Axis.horizontal,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(value, style: TextStyle(color: Colors.white)),
              ]),
        ));
  }
}

class OtherLogin extends StatelessWidget {
  Function onPress;

  OtherLogin(this.onPress, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(0, 0, 0, 20.0),
      child: Center(
        child: GestureDetector(
            onTap: this.onPress,
            child: Column(
              children: [
                Icon(Icons.wb_cloudy),
                Text(
                  "微信登录",
                  style: TextStyle(fontSize: 16.0,height:0.6),
                )
              ],
            )),
      ),
    );
  }
}

class UserInfoEt extends StatelessWidget {
  TextEditingController etController;
  String label;
  bool isPd;

  UserInfoEt(this.label, this.etController, {this.isPd = false, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
        padding: EdgeInsets.fromLTRB(10.0, 0, 10.0, 0),
        child: TextField(
            style: TextStyle(fontSize: 14.0,height: 1.0),
            controller: etController,
            keyboardType: TextInputType.text,
            obscureText: isPd,
            decoration: InputDecoration(
                fillColor:Colors.grey,
                filled: true,
                border: InputBorder.none,
                contentPadding: const EdgeInsets.symmetric(vertical: 5.0),
                labelText: "${this.label}", hintText: "请输入${this.label}")));
  }
}
